/*
 * Tencent is pleased to support the open source community by making Blueking Container Service available.
 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
 * Licensed under the MIT License (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * http://opensource.org/licenses/MIT
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package types

type BcsCommand struct {
	TypeMeta `json:",inline"`
	//ObjectMeta `json:"metadata"`
	Spec *BcsCommandSpec `json:"spec"`
}

type BcsCommandSpec struct {
	CommandTargetRef *TargetRef `json:"commandTargetRef"`
	Taskgroups       []string   `json:"taskgroups"`
	Command          []string   `json:"command"` //["/bin/bash","-c","ps -ef |grep gamesvc"]
	//format: ["k1=v1","k2=v2"]
	Env         []string `json:"env"`  //environments
	User        string   `json:"user"` //root or others
	WorkingDir  string   `json:"workingDir"`
	Privileged  bool     `json:"privileged"`
	ReserveTime int      `json:"reserveTime"` //minutes
}

type BcsCommandStatus struct {
	Taskgroups []*TaskgroupCommandInfo `json:"taskgroups"`
}

type BcsCommandInfo struct {
	Id         string            `json:"id"` //command inspect info id
	CreateTime int64             `json:"createTime"`
	Spec       *BcsCommandSpec   `json:"spec"`
	Status     *BcsCommandStatus `json:"status"`
	// Populated by the system.
	// Read-only.
	// Value must be treated as opaque by clients and .
	ResourceVersion string `json:"-"`
}

type TaskgroupCommandInfo struct {
	TaskgroupId string             `json:"taskgroupId"`
	Tasks       []*TaskCommandInfo `json:"tasks"`
}

type TaskCommandInfo struct {
	TaskId      string              `json:"taskId"` //application taskid
	Status      TaskCommandStatus   `json:"status"`
	Message     string              `json:"message"`
	CommInspect *CommandInspectInfo `json:"commInspect"`
}

type TaskCommandStatus string

const (
	TaskCommandStatusStaging TaskCommandStatus = "staging"
	TaskCommandStatusRunning TaskCommandStatus = "running"
	TaskCommandStatusFinish  TaskCommandStatus = "finish"
	TaskCommandStatusFailed  TaskCommandStatus = "failed"
)

type CommandInspectInfo struct {
	ExitCode int    `json:"exitCode"` // command exitcode,  0: success, >0: failed
	Stdout   string `json:"stdout"`   //command stdout, maxbyte 1024
	Stderr   string `json:"stderr"`   //command stderr, maxbyte 1024
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *BcsCommandInfo) DeepCopyInto(out *BcsCommandInfo) {
	*out = *in
	if in.Spec != nil {
		in, out := &in.Spec, &out.Spec
		*out = new(BcsCommandSpec)
		(*in).DeepCopyInto(*out)
	}
	if in.Status != nil {
		in, out := &in.Status, &out.Status
		*out = new(BcsCommandStatus)
		(*in).DeepCopyInto(*out)
	}
	return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BcsCommandInfoSpec.
func (in *BcsCommandInfo) DeepCopy() *BcsCommandInfo {
	if in == nil {
		return nil
	}
	out := new(BcsCommandInfo)
	in.DeepCopyInto(out)
	return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *BcsCommandSpec) DeepCopyInto(out *BcsCommandSpec) {
	*out = *in
	if in.CommandTargetRef != nil {
		in, out := &in.CommandTargetRef, &out.CommandTargetRef
		*out = new(TargetRef)
		**out = **in
	}
	if in.Taskgroups != nil {
		in, out := &in.Taskgroups, &out.Taskgroups
		*out = make([]string, len(*in))
		copy(*out, *in)
	}
	if in.Command != nil {
		in, out := &in.Command, &out.Command
		*out = make([]string, len(*in))
		copy(*out, *in)
	}
	if in.Env != nil {
		in, out := &in.Env, &out.Env
		*out = make([]string, len(*in))
		copy(*out, *in)
	}
	return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BcsCommandSpec.
func (in *BcsCommandSpec) DeepCopy() *BcsCommandSpec {
	if in == nil {
		return nil
	}
	out := new(BcsCommandSpec)
	in.DeepCopyInto(out)
	return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *BcsCommandStatus) DeepCopyInto(out *BcsCommandStatus) {
	*out = *in
	if in.Taskgroups != nil {
		in, out := &in.Taskgroups, &out.Taskgroups
		*out = make([]*TaskgroupCommandInfo, len(*in))
		for i := range *in {
			if (*in)[i] != nil {
				in, out := &(*in)[i], &(*out)[i]
				*out = new(TaskgroupCommandInfo)
				(*in).DeepCopyInto(*out)
			}
		}
	}
	return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BcsCommandStatus.
func (in *BcsCommandStatus) DeepCopy() *BcsCommandStatus {
	if in == nil {
		return nil
	}
	out := new(BcsCommandStatus)
	in.DeepCopyInto(out)
	return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TaskgroupCommandInfo) DeepCopyInto(out *TaskgroupCommandInfo) {
	*out = *in
	if in.Tasks != nil {
		in, out := &in.Tasks, &out.Tasks
		*out = make([]*TaskCommandInfo, len(*in))
		for i := range *in {
			if (*in)[i] != nil {
				in, out := &(*in)[i], &(*out)[i]
				*out = new(TaskCommandInfo)
				(*in).DeepCopyInto(*out)
			}
		}
	}
	return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskgroupCommandInfo.
func (in *TaskgroupCommandInfo) DeepCopy() *TaskgroupCommandInfo {
	if in == nil {
		return nil
	}
	out := new(TaskgroupCommandInfo)
	in.DeepCopyInto(out)
	return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TaskCommandInfo) DeepCopyInto(out *TaskCommandInfo) {
	*out = *in
	if in.CommInspect != nil {
		in, out := &in.CommInspect, &out.CommInspect
		*out = new(CommandInspectInfo)
		**out = **in
	}
	return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskCommandInfo.
func (in *TaskCommandInfo) DeepCopy() *TaskCommandInfo {
	if in == nil {
		return nil
	}
	out := new(TaskCommandInfo)
	in.DeepCopyInto(out)
	return out
}
